(function () {
    'use strict';

    angular.module('app.pagos')
        .controller('ListarPagosCtrl', ['$scope', '$filter', 'PagosService', ListarPagosCtrl]);

    function ListarPagosCtrl ($scope, $filter, PagosService){
        var init;

        $scope.listOfItems = [];

        $scope.searchKeywords = '';

        $scope.filteredStores = [];

        $scope.row = '';

        $scope.select = function(page) {
            var end, start;
            start = (page - 1) * $scope.numPerPage;
            end = start + $scope.numPerPage;
            return $scope.currentPageItems = $scope.filteredStores.slice(start, end);
        };

        $scope.onFilterChange = function() {
            $scope.select(1);
            $scope.currentPage = 1;
            return $scope.row = '';
        };

        $scope.onNumPerPageChange = function() {
            $scope.select(1);
            return $scope.currentPage = 1;
        };

        $scope.onOrderChange = function() {
            $scope.select(1);
            return $scope.currentPage = 1;
        };

        $scope.search = function() {
            $scope.filteredStores = $filter('filter')($scope.listOfItems, $scope.searchKeywords);
            return $scope.onFilterChange();
        };

        $scope.order = function(rowName) {
            if ($scope.row === rowName) {
                return;
            }
            $scope.row = rowName;
            $scope.filteredStores = $filter('orderBy')($scope.listOfItems, rowName);
            return $scope.onOrderChange();
        };

        $scope.numPerPageOpt = [3, 5, 10, 20];

        $scope.numPerPage = $scope.numPerPageOpt[2];

        $scope.currentPage = 1;

        $scope.currentPageItems = [];

        init = function() {
            $scope.search();
            return $scope.select($scope.currentPage);
        };
/*
        PagosService.Listar()
            .success(function (response) {
                $scope.listOfItems = angular.fromJson(response);
                init();
            }).error(function () {
                console.log(arguments)
            });
*/
        init();
    }

})();